package objetos;






import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.Random;

import javax.imageio.ImageIO;

import canvas.CanvasMenuPrincipal2;

public class CanvasMenuPrincipal extends myCanvas{

	public static CanvasMenuPrincipal instance = null;


	BufferedImage menuImage;

	BufferedImage start;

	long timerCompra, timerVenda, timerAnimStart;
	int duracaoAnimacaoStart, posX, posY;

	boolean mouseOver = false;


	Random rnd = new Random();

	long diftime, timerCLick;

	public CanvasMenuPrincipal() {

		menuImage = GamePanel.loadImage("./../menuStart.png");

		start = GamePanel.loadImage("./../start.png");

		posX = (GamePanel.WIDTH/2) + (start.getWidth()/2);

		posY = (GamePanel.HEIGHT/2) + (start.getHeight()+200/2);

		instance = this;		


	}

	@Override
	public void SimulaSe(long diftime) {
		this.diftime = diftime;
		//System.out.print("\n MAPA ATUAL DO SHOP => " + CanvasGame.MapaAtual+ "\n");
		CanvasGame.instance.heroi.life = 100;

		//CanvasGame.instance.dinheiro = 0;

		timerCLick += this.diftime;
		timerAnimStart += this.diftime;
		checaMouseLoja();

	}

	private void checaMouseLoja() {

		if(CanvasGame.instance.FIRE == true && timerCLick > 500){
			timerCLick = 0;
			CanvasGame.instance.heroi.X= 100; 
			CanvasGame.instance.heroi.Y= 300;

			CanvasGame.instance.FIRE = false;
			if (CanvasMenuSelectDificuldade.instance == null) {
//				CanvasMenuSelectDificuldade selectDificuldade = new CanvasMenuSelectDificuldade();

			}
//			GamePanel.canvasAtivo = CanvasMenuSelectDificuldade.instance;

		}

	}


	public void DesenhaSe(Graphics2D dbg) {


		dbg.drawImage(menuImage, 0, 0, null); // tamanho da imagem

		if(timerAnimStart > 500){ // tempo ate aparecer novamente
			if(duracaoAnimacaoStart > 100){
				timerAnimStart = 0;
				duracaoAnimacaoStart = 0;
			}
			duracaoAnimacaoStart++; // duracao da exibicao do start na tela

			dbg.drawImage(start, posX, posY, null);

		}



	}

	@Override
	public void keyPressed(KeyEvent e) {
		// TODO Auto-generated method stub
		int keyCode = e.getKeyCode();
		
		//CanvasGame.instance.listadePetdoveiculo.clear();
		//CanvasGame.instance.listadePetSystem.clear();

		//if (keyCode == KeyEvent.VK_ENTER) {
		//	GamePanel.canvasAtivo = CanvasGame.instance;	
		//}

	}

	@Override
	public void keyReleased(KeyEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseMoved(MouseEvent e) {
		//System.out.print("MOVEU O MOUSEEEEEEEEEEEEE ");


	}

	@Override
	public void mouseDragged(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub

	}


	@Override
	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub
		//System.out.print("Clicou AEEEEEEEEEEEEEEH ");
		CanvasGame.instance.MouseX = e.getX();
		CanvasGame.instance.MouseY = e.getY();
		int cont = 0;

	}

	public static BufferedImage loadImage(String source) {
		BufferedImage image = null;
		try {
			BufferedImage tmp = ImageIO.read(CanvasGame.instance.getClass()
					.getResource(source));
			image = new BufferedImage(tmp.getWidth(), tmp.getHeight(),
					BufferedImage.TYPE_INT_ARGB);
			image.getGraphics().drawImage(tmp, 0, 0, null);
			tmp = null;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return image;
	}

	@Override
	public void mouseClicked(MouseEvent e) {
		System.out.print("CLICOU NO MOUSE AEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEH");

	}



}
